<?php
namespace app\admin\controller;
use app\common\model\Config as ConfigModel;
use app\common\model\MallConfig as MallConfigModel;

class Config extends Base
{
    public function __construct () {
        parent::__construct();
    }
    /* 全局配置 */
    public function list () {
        $config = ConfigModel::getConfig();
        $config['mall_id'] = $this->mall['id']?$this->mall['id']:1;
        $config['manager_name'] = $this->manager['name'];
        $config['manager_id'] = $this->manager['id'];
        $config['is_super'] = $this->manager['is_super'];
        $config['web_domain'] = request()->domain();
        $config['site_menu'] = $config['site_menu']?json_decode($config['site_menu'],true):false;
        //当前反馈月份
        $config['fankui_date'] = date('Y年m月',strtotime('-14 days'));
//        反馈结束倒计时
        $five_date = date('d',strtotime('-14 days'));
        $five_last = date('t',strtotime('-14 days'));
        $djs = $five_last-$five_date;
        $config['djs'] = $djs;
        return returnJson(0,'',$config);
    }

    /* 修改配置 */
    public function update () {
        $data = input();
        if($data['chat_ban_word']) {
            $data['chat_ban_word'] = str_replace('，',',',$data['chat_ban_word']);
        }
        ConfigModel::saveConfig($data);
        return returnJson(0,'更新成功');
    }

    /* 分公司的配置 */
    public function mallList () {
        $config = MallConfigModel::getConfig($this->mall['id']);
        $config['mall_id'] = $this->mall['id']?$this->mall['id']:0;
        $config['money'] =$this->mall['money'];
        $config['authorizer_appid'] = $this->mall['authorizer_appid'];
        $config['share_picture'] = $config['share_picture']?$config['share_picture']:'';
        $config['shop_ad_video'] = $config['shop_ad_video']?$config['shop_ad_video']:'';
        $config['shop_ad_picture'] = $config['shop_ad_picture']?$config['shop_ad_picture']:'';
        $config['shop_qrcode'] = $config['shop_qrcode']?$config['shop_qrcode']:'';
        if($this->mall['detail']) {
            $config['mall_info'] = json_decode($this->mall['detail'],true);
        }
        $config['urlList'] = [
            '课程首页' => request()->domain()."/m?mall_id={$this->mall['id']}",
            //'积分商城' => request()->domain()."/m/shop2/pages/index/index?mall_id={$this->mall['id']}",
            //'生态商城' => request()->domain()."/m/shop3/pages/index/index?mall_id={$this->mall['id']}",
            '聊天室' => request()->domain()."/m/chat/pages/index/index?mall_id={$this->mall['id']}",
            '加盟' => request()->domain()."/m/shop1/pages/jiameng/index?mall_id={$this->mall['id']}",
            '个人中心' => request()->domain()."/m/shop1/pages/me/index?mall_id={$this->mall['id']}",
            '推广' => request()->domain()."/m/chat/pages/tuiguang/index?mall_id={$this->mall['id']}",
        ];
        return returnJson(0,'',$config);
    }

    /* 修改配置 */
    public function mallUpdate () {
        $data = input();
        MallConfigModel::saveConfig($this->mall['id'],$data);
        return returnJson(0,'更新成功');
    }
    public function getPrintInfo(){
        //returnJson(0,'查询成功',config('printer_name'));
        echo json_encode(array('code'=>0,'msg'=>'查询成功','data'=>array('print_name'=>config('printer_name'))));
    }

    public function savePrintName(){
        $data['printer_name']=input('post.print_name');
        if(empty($data['printer_name'])){
            $this->ajax(202,'打印机名字不能为空');
        }
        \app\common\model\Config::saveConfig($data);
        $this->ajax(200,'修改成功');
    }
}
